package service.impl;

import com.github.pagehelper.PageHelper;
import mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Comment;
import service.ICommentService;

import java.util.List;

/**
 * 评论服务层实现类
 */
@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;
    @Override
    public int addComment(Comment comment) {
        int i = commentMapper.insertSelective(comment);
        return i;
    }

    @Override
    public List<Comment> getCommentsByArticleId(Integer articleId, int pageSize,int pageCurrent) {
        PageHelper.startPage(pageCurrent, pageSize);
        List<Comment> comments = commentMapper.selectByArticleId(articleId);
        return comments;
    }

    @Override
    public Comment getCommentById(Integer articleId) {
        Comment comment = commentMapper.selectByPrimaryKey(articleId);
        return comment;
    }

    @Override
    public List<Comment> getCommentsByReplyUserIdAndNotDel(Integer userId) {
        List<Comment> comments = commentMapper.selectByReplyUserIdAndNotDel(userId);
        return comments;
    }

    @Override
    public List<Comment> getCommentsByReplyUserIdAndStatus(Integer userId,int status) {
        List<Comment> comments = commentMapper.selectByReplyUserIdAndCommentStatus(userId,status);
        return comments;
    }

    @Override
    public int getCommentCountByArticleId(Integer articleId) {
        int count = commentMapper.selectCountByArticleId(articleId);
        return count;
    }

    @Override
    public int modifyCommentByCommentId(Comment comment) {
        int count = commentMapper.updateByPrimaryKeySelective(comment);
        return count;
    }

    @Override
    public int setCommendStatusByReplyUserId(Integer replyUserId, int status) {
        int count = commentMapper.updateCommentStatusByReplyUserId(replyUserId,status);
        return count;
    }
}
